import collections
class Solution(object):
    def criticalConnections(self, n, connections):
        d = collections.defaultdict(set)
        for u,v in connections:
            d[u].add(v)
            d[v].add(u)
        time = [-1] * n
        low = [-1] * n
        st = []
        self.index = 0
        node_index = [-1] * n
        self.group_index = 0
        def dfs(last_node, node):
            if time[node] == -1:
                st.append(node)
                time[node] = self.index
                low[node] = self.index
                self.index += 1
                for next_node in d[node]:
                    if next_node != last_node:
                        low[node] = min(low[node], dfs(node, next_node))
                if time[node] == low[node]:
                    while True:
                        u = st.pop()
                        node_index[u] = self.group_index
                        if u == node:
                            self.group_index += 1
                            break
                return low[node]
            else:
                return time[node]
        dfs(-1, 0)
        ans = []
        for u, v in connections:
            if node_index[u] != node_index[v]:
                ans.append([u, v])
        return ans


data = Solution()
n = 4
connections = [[0,1],[1,2],[2,0],[1,3]]
print(data.criticalConnections(n, connections))